package vn.itplus.nguyettm;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		final ArrayList<itemModel> list = new ArrayList<itemModel>();
		ListView listView = (ListView) findViewById(R.id.listView1);
		itemModel item = new itemModel("Aamirakhan", getResources()
				.getDrawable(R.drawable.aamirkhan), "01665133179");
		list.add(item);
		item = new itemModel("Barack Obama", getResources().getDrawable(
				R.drawable.barackobama), "0988386372");
		list.add(item);
		item = new itemModel("Yoona", getResources().getDrawable(
				R.drawable.yoona), "090567999");
		list.add(item);
		itemAdapter adapter = new itemAdapter(this, list);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View v, int position,
					long arg3) {
				Intent i = new Intent(getBaseContext(),
						itemDetailActivity.class);
				i.putExtra("Name", list.get(position).getName());
				i.putExtra("Phone", list.get(position).getPhone());
				startActivity(i);
			}

		});
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
